<template>
  <view @click.stop="nav" :class="{ 'y-expand-scope': expandScope }"><slot></slot></view>
</template>

<script>
import util from '../../lib/util.js';
export default {
  props: {
    url: null,
    init: null,
    options: {
      type: Object,
      default: {}
    },
    redirectTo: {
      type: Boolean,
      default: false
    },
    reLaunch:{type:String,default:''},
    expandScope: {
      type: Boolean,
      default: false
    }
  },
  data() {
    return {};
  },
  methods: {
    nav() {
      const that = this;
      let { url, options,reLaunch } = that;
      if(reLaunch){
        uni.reLaunch({
          url:reLaunch
        })
      }
      const method = this.redirectTo ? 'redirectTo' : 'navigateTo';
      if (url) {
        uni[method]({
          url: util.makeUrlCarryOptions(url, options),
          events: {
            comeBackData(data) {
              that.$emit('comeBackData', data);
            }
          },
          success: res => {
            res.eventChannel?.emit('initData', that.init);
          }
        });
      } else uni.navigateBack();
    }
  }
};
</script>

<style></style>
